/*
===========================================================================
This source file is part of DyLab (Dynamic Laboratory)
For the latest info, see http://code.google.com/p/dylab/

Copyright (c) 2006-2008 Lukas Krejci
(krejci.lukas@volny.cz)

This file is part of DyLab.

    DyLab is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    DyLab is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with DyLab.  If not, see <http://www.gnu.org/licenses/>.
===========================================================================
*/

#ifndef __dylab_ComponentManager_h__
#define __dylab_ComponentManager_h__

//===========================================================================================
#include <dylab/utils/Singleton.h>
#include <dylab/utils/types/DynamicCast.h>
#include <dylab/utils/components/ModuleManager.h>
#include <dylab/utils/components/IComponent.h>

//===========================================================================================
namespace dylab {

    /** 
     *
     */
    class DYLAB_EXPORT ComponentManager 
        : public Singleton<ComponentManager>
    {
    private:
        static String buildComponentFullName(const String & _componentTypeName, const String & _componentName)
                { return _componentTypeName + "." + _componentName; }

    private:
        //
        class ComponentInfo
        {
        public:            
            String mModuleName;

        public:                       
            ComponentInfo(const String & _moduleName);            
            String getModuleName() const;
        };
        //-----------------------------------------------------------------------------

    private:
        // manages modules containing _components
        ModuleManager mModuleMgr;
        // container (compId -> compName hash-map) of all registered component classes
        typedef HashContainer<String, String> ComponentTypeNames;
        ComponentTypeNames mComponentTypeNames;
        // container (compName -> IComponent* hash-map) of all loaded _components
        typedef HashObjContainer<String, ComponentInfo> Components;
        Components mComponents;

    public:
        ComponentManager();
        ~ComponentManager();                

        /**
         *
         */
        void setModuleBasePath(const String & _basePath);

        /**
         *
         */
        void registerComponentType(const String & _compTypeId, const String & _compTypeName);

        /**
         *
         */
        String translateComponentTypeIdToName(const String & _compTypeId) const;

        /**
         *
         */
        String getComponentFullName(const String & _compTypeId, const String & _compName) const;

        /**
         *
         */
        void registerComponent(const String & _moduleName, const String & _compTypeName, const String & _compName);

        /**
         *
         */
        IComponent * createComponent(const String & _fullComponentName);                

		/**
		 * Loads the module settings from a file of the given name.
		 */
		void load(const String & _fileName);
    };
}
//===========================================================================================
#endif // __dylab_ComponentManager_h__
